import Vue from 'vue'

// import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

// console.log(process.env)
import * as echarts from 'echarts'

Vue.prototype.$echarts = echarts

Vue.directive('permission', {
  // 会在指令作用的元素插入到页面完成后触发
  inserted (el, binding) {
    // el-指令作用元素dom对象
    const points = store.getters.btnList
    if (!points.includes(binding.value)) {
      // 移除或则禁用
      el.remove()
      // el.disabled=true
    }
  }
})

Vue.use(ElementUI)
// const cors = require('cors')
// Vue.use(cors()) // 使用cors中间件

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})

Vue.prototype.openLoading = function () {
  const loading = this.$loading({
    lock: true,
    text: '加载中',
    spinner: 'el-icon-loading',
    background: 'rgba(255,255, 255, 0.8)',
    fullscreen: true
  })
  setTimeout(function () {
    loading.close()
  }, 3000)
  return loading
}
